package cn.yhp.chatgpt.data.domain.weixin.service.validate;

import cn.yhp.chatgpt.data.domain.weixin.service.IWeiXinValidateService;
import cn.yhp.chatgpt.data.types.sdk.weixin.SignatureUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * @author yhp
 * @description
 * @date 2024/2/4
 */
@Service
public class WeiXinValidateService implements IWeiXinValidateService {

    @Value("${wx.config.token}")
    private String token;

    @Override
    public boolean checkSign(String signature, String timestamp, String nonce,String echostr) {
        if (StringUtils.isAnyBlank(signature, timestamp, nonce, echostr)) {
            throw new IllegalArgumentException("请求参数非法，请核实!");
        }
        return SignatureUtil.check(token,signature,timestamp,nonce);
    }
}
